package com.nineclock.document.controller;


import com.nineclock.common.entity.Result;
import com.nineclock.doc.DocControllerApi;
import com.nineclock.document.dto.DocFileHistoryDto;
import com.nineclock.document.dto.DocFolderDto;
import com.nineclock.document.service.DocFolderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.nineclock.document.dto.DocumentDto;
import com.nineclock.document.service.DocService;

import java.util.List;


@RestController
//@RequestMapping("/document")
public class DocController implements DocControllerApi {

    @Autowired
    DocService docService;

    @GetMapping("/listFolderAndFile")
    public Result<DocumentDto> listFolderAndFIle(@RequestParam(name = "parentFoldID", defaultValue = "0") Long parentFoldId,
                                                 @RequestParam(name = "keyword", required = false) String keyword) {
        ///document/listFolderAndFile
        DocumentDto documentDto = docService.listFolderAndFIle(parentFoldId, keyword);

        return Result.success(documentDto);
    }

    @PutMapping("/{fileId}/{status}")
    public Result banOrLift(@PathVariable("fileId") Long fileId,
                            @PathVariable("status") Short status) {

        docService.banOrLift(fileId, status);
        return Result.success();
    }

    @Autowired
    private DocFolderService docFolderService;


    /*新增文件夹*/
    @Override
    @PostMapping("/insertFolder")
    public Result insertFolder(@RequestBody DocFolderDto docFolderDto) {
        docFolderService.insertFolder(docFolderDto);
        return Result.success();
    }
    /**
     * 查询文件历史记录
     * @param field
     * @return
     */
    @GetMapping("/history/{field}")
    public Result<List<DocFileHistoryDto>> queryhistory(@PathVariable(value = "field") Long field) {
        List<DocFileHistoryDto> list = docService.queryhistory(field);
        return Result.success(list);
    }
}








